<?php
class Grillas_model extends CI_Model{
    function __construct(){
      parent::__construct();
   }
   public function ayudasTecnicas($transaccion){
    //Variables del jqgrid
    $page = $this->input->post('page'); // get the requested page
    $limit = $this->input->post('rows'); // get how many rows we want to have into the grid
    $sidx = $this->input->post('sidx'); // get index row - i.e. user click to sort
    $sord = $this->input->post('sord'); // get the direction
    if(!$sidx) $sidx =1;
    
    if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
        header("Content-type: application/xhtml+xml;charset=utf-8");
    } else {
        header("Content-type: text/xml;charset=utf-8");
    }
    $et = ">";
    echo "<?xml version='1.0' encoding='utf-8'?$et\n";
    echo "<rows>";
    $sql = "select count(transaccion) as total from temporal where tempInd = 'ayudasTecnicas' and transaccion = '$transaccion' ";
      $query = $this->db->query($sql);
      $obj = $query->result();
    $count = $obj[0]->total;
    if( $count >0 ) $total_pages = ceil($count/$limit);
    else $total_pages = 0;
    if ($page > $total_pages) $page=$total_pages;
    $start = $limit*$page - $limit; // do not put $limit*($page - 1)
    $start = ($start > 0)?$start:0;
    $sql = "select temp.tempId,ayuda.tipAyudaTecnicaDesc,ayuda.tipAyudaTecnicaClase,temp.tempText1 from temporal temp
            inner join tipayudastecnicas ayuda on ayuda.tipAyudaTecnicaId = temp.tempVarchar2 where temp.tempInd = 'ayudasTecnicas' and temp.transaccion = '$transaccion' ORDER BY $sidx $sord LIMIT $start , $limit";
     echo "<page>".$page."</page>";
    echo "<total>".$total_pages."</total>";
    echo "<records>".$count."</records>"; // be sure to put text data in CDATA$sql
//    echo "<sql>$sql</sql>";
     $query = $this->db->query($sql);
     //Consulta cantidad
     foreach ($query->result() as $value) {
        echo "<row id='".$value->tempId."'>";
        echo "<cell></cell>";
        echo "<cell>".$value->tipAyudaTecnicaDesc."</cell>";
        echo "<cell>".$value->tipAyudaTecnicaClase."</cell>";
        echo "<cell>".$value->tempText1."</cell>";
        echo "</row>";
     }
    echo "</rows>";
  }
  public function administaPer($transaccion){
    //Variables del jqgrid
    $page = $this->input->post('page'); // get the requested page
    $limit = $this->input->post('rows'); // get how many rows we want to have into the grid
    $sidx = $this->input->post('sidx'); // get index row - i.e. user click to sort
    $sord = $this->input->post('sord'); // get the direction
    if(!$sidx) $sidx =1;

    if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
        header("Content-type: application/xhtml+xml;charset=utf-8");
    } else {
        header("Content-type: text/xml;charset=utf-8");
    }
    $et = ">";
    echo "<?xml version='1.0' encoding='utf-8'?$et\n";
    echo "<rows>";
    $sql = "select count(transaccion) as total from temporal where tempInd = 'administraPersonas' and transaccion = '$transaccion' ";
      $query = $this->db->query($sql);
      $obj = $query->result();
    $count = $obj[0]->total;
    if( $count >0 ) $total_pages = ceil($count/$limit);
    else $total_pages = 0;
    if ($page > $total_pages) $page=$total_pages;
    $start = $limit*$page - $limit; // do not put $limit*($page - 1)
    $start = ($start > 0)?$start:0;
    $sql = "select temp.tempId,temp.tempVarchar1,temp.tempVarchar2,temp.tempVarchar3,temp.tempDate1,temp.tempDate2,temp.tempInt1,tipAdm.tipAdministradoraDesc,adm.administradoraNombre from temporal temp
            inner join tipadministradoras tipAdm on tipAdm.tipAdministradoraTip = temp.tempVarchar1
            inner join administradoras adm on adm.administradoraId = temp.tempInt1 where temp.tempInd = 'administraPersonas' and temp.transaccion = '$transaccion' ORDER BY $sidx $sord LIMIT $start , $limit";
     echo "<page>".$page."</page>";
    echo "<total>".$total_pages."</total>";
    echo "<records>".$count."</records>"; // be sure to put text data in CDATA$sql
//    echo "<sql>$sql</sql>";
     $query = $this->db->query($sql);
     //Consulta cantidad
     foreach ($query->result() as $value) {
        echo "<row id='".$value->tempId."'>";
        echo "<cell></cell>";
        echo "<cell>".$value->tipAdministradoraDesc."</cell>";
        echo "<cell>".$value->administradoraNombre."</cell>";
        echo "<cell>".$value->tempVarchar2."</cell>";
        echo "<cell>".$value->tempVarchar3."</cell>";
        echo "<cell>".$value->tempDate1."</cell>";
        echo "<cell>".$value->tempDate2."</cell>";
        echo "</row>";
     }
    echo "</rows>";
  }
  public function explaboral($transaccion){
    //Variables del jqgrid
    $page = $this->input->post('page'); // get the requested page
    $limit = $this->input->post('rows'); // get how many rows we want to have into the grid
    $sidx = $this->input->post('sidx'); // get index row - i.e. user click to sort
    $sord = $this->input->post('sord'); // get the direction
    if(!$sidx) $sidx =1;

    if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
        header("Content-type: application/xhtml+xml;charset=utf-8");
    } else {
        header("Content-type: text/xml;charset=utf-8");
    }
    $et = ">";
    echo "<?xml version='1.0' encoding='utf-8'?$et\n";
    echo "<rows>";
    $sql = "select count(transaccion) as total from temporal where tempInd = 'exp' and transaccion = '$transaccion' ";
      $query = $this->db->query($sql);
      $obj = $query->result();
    $count = $obj[0]->total;
    if( $count >0 ) $total_pages = ceil($count/$limit);
    else $total_pages = 0;
    if ($page > $total_pages) $page=$total_pages;
    $start = $limit*$page - $limit; // do not put $limit*($page - 1)
    $start = ($start > 0)?$start:0;
    $sql = "select temp.tempId,temp.tempVarchar1,temp.tempVarchar2,temp.tempVarchar3,temp.tempDate1,temp.tempDate2,temp.tempVarchar4,temp.tempText1 from temporal temp where temp.tempInd = 'exp' and temp.transaccion = '$transaccion' ORDER BY $sidx $sord LIMIT $start , $limit";
     echo "<page>".$page."</page>";
    echo "<total>".$total_pages."</total>";
    echo "<records>".$count."</records>"; // be sure to put text data in CDATA$sql
//    echo "<sql>$sql</sql>";
     $query = $this->db->query($sql);
     //Consulta cantidad
     foreach ($query->result() as $value) {
        echo "<row id='".$value->tempId."'>";
        echo "<cell></cell>";
        echo "<cell>".$value->tempVarchar1."</cell>";
        echo "<cell>".$value->tempVarchar2."</cell>";
        echo "<cell>".$value->tempDate1."</cell>";
        echo "<cell>".$value->tempDate2."</cell>";
        echo "<cell>".$value->tempText1."</cell>";
        echo "<cell>".$value->tempVarchar3."</cell>";
        echo "<cell>".$value->tempVarchar4."</cell>";
        echo "</row>";
     }
    echo "</rows>";
  }
    public function formAcade($transaccion){
    //Variables del jqgrid
    $page = $this->input->post('page'); // get the requested page
    $limit = $this->input->post('rows'); // get how many rows we want to have into the grid
    $sidx = $this->input->post('sidx'); // get index row - i.e. user click to sort
    $sord = $this->input->post('sord'); // get the direction
    if(!$sidx) $sidx =1;

    if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
        header("Content-type: application/xhtml+xml;charset=utf-8");
    } else {
        header("Content-type: text/xml;charset=utf-8");
    }
    $et = ">";
    echo "<?xml version='1.0' encoding='utf-8'?$et\n";
    echo "<rows>";
    $sql = "select count(transaccion) as total from temporal tmp
            left join tipformacion tipFo on tipFo.`tipFormacionId` = tmp.tempVarchar3
            left join instituciones inst on inst.`institucionId` = tmp.`tempVarchar1` 
            where tmp.tempInd = 'aca' and tmp.transaccion = '$transaccion' ";
      $query = $this->db->query($sql);
      $obj = $query->result();
    $count = $obj[0]->total;
    if( $count >0 ) $total_pages = ceil($count/$limit);
    else $total_pages = 0;
    if ($page > $total_pages) $page=$total_pages;
    $start = $limit*$page - $limit; // do not put $limit*($page - 1)
    $start = ($start > 0)?$start:0;
    $sql = "select temp.tempId,temp.tempVarchar1,temp.tempVarchar2,tipFo.`tipFormacion`,temp.tempVarchar5,temp.tempDate1,temp.tempDate2,temp.tempVarchar4,temp.`tempVarchar6` from temporal temp
            left join tipformacion tipFo on tipFo.`tipFormacionId` = temp.tempVarchar3
            where temp.tempInd = 'aca' and temp.transaccion = '$transaccion' ORDER BY $sidx $sord LIMIT $start , $limit";
     echo "<page>".$page."</page>";
    echo "<total>".$total_pages."</total>";
    echo "<records>".$count."</records>"; // be sure to put text data in CDATA$sql
     $query = $this->db->query($sql);
     //Consulta cantidad
     foreach ($query->result() as $value) {
        echo "<row id='".$value->tempId."'>";
        echo "<cell></cell>";
        echo "<cell>".$value->tempVarchar1."</cell>";
        echo "<cell>".$value->tipFormacion."</cell>";
        echo "<cell>".$value->tempVarchar2."</cell>";
        echo "<cell>".$value->tempVarchar4."</cell>";
        echo "<cell>".$value->tempVarchar5."</cell>";
        echo "<cell>".$value->tempDate1."</cell>";
        echo "<cell>".$value->tempDate2."</cell>";
        echo "</row>";
     }
    echo "</rows>";
  }
    public function discapa($transaccion){
    //Variables del jqgrid
    $page = $this->input->post('page'); // get the requested page
    $limit = $this->input->post('rows'); // get how many rows we want to have into the grid
    $sidx = $this->input->post('sidx'); // get index row - i.e. user click to sort
    $sord = $this->input->post('sord'); // get the direction
    if(!$sidx) $sidx =1;

    if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
        header("Content-type: application/xhtml+xml;charset=utf-8");
    } else {
        header("Content-type: text/xml;charset=utf-8");
    }
    $et = ">";
    echo "<?xml version='1.0' encoding='utf-8'?$et\n";
    echo "<rows>";
    $sql = "select count(transaccion) as total from temporal where tempInd = 'discapacidad' and transaccion = '$transaccion' ";
      $query = $this->db->query($sql);
      $obj = $query->result();
    $count = $obj[0]->total;
    if( $count >0 ) $total_pages = ceil($count/$limit);
    else $total_pages = 0;
    if ($page > $total_pages) $page=$total_pages;
    $start = $limit*$page - $limit; // do not put $limit*($page - 1)
    $start = ($start > 0)?$start:0;
    $sql = "select disca.tipDiscapacidad,temp.tempText1,temp.tempText2,temp.tempId from temporal temp
            inner join tipdiscapacidades disca on disca.tipDiscapacidadId = temp.tempVarchar1 where temp.tempInd = 'discapacidad' and temp.transaccion = '$transaccion' ORDER BY $sidx $sord LIMIT $start , $limit";
     echo "<page>".$page."</page>";
    echo "<total>".$total_pages."</total>";
    echo "<records>".$count."</records>"; // be sure to put text data in CDATA$sql
//    echo "<sql>$sql</sql>";
     $query = $this->db->query($sql);
     //Consulta cantidad
     foreach ($query->result() as $value) {
        echo "<row id='".$value->tempId."'>";
        echo "<cell></cell>";
        echo "<cell>".$value->tipDiscapacidad."</cell>";
        echo "<cell>".$value->tempText1."</cell>";
        echo "</row>";
     }
    echo "</rows>";
  }
  
}
?>
